Load libraries (packages)

library("respR") ## respirometry/slope analysis
library("tidyverse") ## data manipulation

Set working directory

setwd("[PATH TO DIRECTORY]")

System1 - Dell

Importing data from firesting for resting

preexperiment_date <- "03 April 2023 11 29AM/All"
postexperiment_date <- "03 April 2023 05 02PM/All"

##--- last fish run in trial ---##
experiment_date <- "03 April 2023 01 37PM/Oxygen"
experiment_date2 <- "03 April 2023 01 37PM/All"

firesting <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1 <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_date2,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

System2 - Asus

Importing data from firesting for resting

preexperiment_date_asus <- "03 April 2023 11 19AM/All"
postexperiment_date_asus <- "03 April 2023 04 07PM/All"

##--- last fish run in trial ---##
experiment_date_asus <- "03 April 2023 12 53PM/Oxygen"
experiment_date2_asus <- "03 April 2023 12 53PM/All"

firesting_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19)

Cycle_1_asus <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Cycle_last_asus <-read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_date2_asus,"slopes/Cycle_21.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 

Chamber volumes

chamber1_dell = 0.04650
chamber2_dell = 0.04593
chamber3_dell = 0.04977
chamber4_dell = 0.04860 

chamber1_asus = 0.04565
chamber2_asus = 0.04573+0.00385
chamber3_asus = 0.04551+0.00322
chamber4_asus = 0.04791+0.00277

Date_tested="2023-04-03"
Clutch = "57" 
Male = "CARL241" 
Female = "CARL239"
Population = "Arlington reef"
Tank =319 
salinity =36 
Date_analysed = Sys.Date() 

Replicates

1

Enter specimen data

Replicate = 1 
mass = 0.0004180
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 April 2023 01 05PM/Oxygen"
experiment_mmr_date2 <- "03 April 2023 01 05PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0009187526

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] 0.0008580431

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.66
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME) 
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  7  8  9 10 11 12 13 14 15 16 18 19 20 21 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.30
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   4    1     222.0632 -0.01321926 0.982      NA 1507   1739  9441.59
## 2:   7    1     239.4858 -0.01282281 0.983      NA 2982   3215 11061.36
## 3:  12    1     276.5312 -0.01301005 0.990      NA 5451   5685 13761.04
## 4:  13    1     273.5771 -0.01230413 0.983      NA 5946   6180 14301.85
## 5:  16    1     285.0490 -0.01177765 0.980      NA 7427   7660 15920.92
## 6:  19    1     328.0483 -0.01313076 0.967      NA 8909   9142 17541.53
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1:  9696.89 97.034 93.691 -0.01321926 0.0009028936   -0.01412215 -0.01412215
## 2: 11316.63 97.309 94.126 -0.01282281 0.0008931863   -0.01371599 -0.01371599
## 3: 14016.45 97.205 93.983 -0.01301005 0.0008770066   -0.01388706 -0.01388706
## 4: 14557.40 97.246 94.235 -0.01230413 0.0008737651   -0.01317790 -0.01317790
## 5: 16175.65 97.226 94.330 -0.01177765 0.0008640644   -0.01264171 -0.01264171
## 6: 17796.31 97.262 93.996 -0.01313076 0.0008543519   -0.01398511 -0.01398511
##    oxy.unit time.unit volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.000418   NA 36 27 1.013253 -0.1603990
## 2:     %Air       sec 0.0486 0.000418   NA 36 27 1.013253 -0.1557859
## 3:     %Air       sec 0.0486 0.000418   NA 36 27 1.013253 -0.1577288
## 4:     %Air       sec 0.0486 0.000418   NA 36 27 1.013253 -0.1496742
## 5:     %Air       sec 0.0486 0.000418   NA 36 27 1.013253 -0.1435842
## 6:     %Air       sec 0.0486 0.000418   NA 36 27 1.013253 -0.1588424
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -383.7297          NA  mgO2/hr/kg   -383.7297
## 2:   -372.6934          NA  mgO2/hr/kg   -372.6934
## 3:   -377.3415          NA  mgO2/hr/kg   -377.3415
## 4:   -358.0722          NA  mgO2/hr/kg   -358.0722
## 5:   -343.5028          NA  mgO2/hr/kg   -343.5028
## 6:   -380.0058          NA  mgO2/hr/kg   -380.0058
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
57 1 CARL241 CARL239 Arlington reef 319 0.000418 ch4 Dell 0.0486 2023-04-03 2024-06-26 good/good 36 27 374.3685 0.1564861 0.981

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.66
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  5  6  7  8  9 11 13 15 16 17 18 19 20 21 22 23 24 26
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.38
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     268.0955 -0.02859817 0.9975809      NA 184    237 6046.92
##   2:  NA    2     268.0964 -0.02859792 0.9975784      NA 186    239 6049.10
##   3:  NA    3     268.0268 -0.02858670 0.9975480      NA 185    238 6048.01
##   4:  NA    4     268.0246 -0.02858659 0.9975695      NA 183    236 6045.83
##   5:  NA    5     267.9326 -0.02857083 0.9975172      NA 187    240 6050.19
##  ---                                                                       
## 210:  NA  210     167.2101 -0.01165309 0.9418308      NA   5     58 5845.64
## 211:  NA  211     165.4567 -0.01135471 0.9378336      NA   4     57 5844.54
## 212:  NA  212     162.8920 -0.01091802 0.9357689      NA   3     56 5843.45
## 213:  NA  213     160.3454 -0.01048444 0.9301865      NA   2     55 5842.37
## 214:  NA  214     157.7203 -0.01003735 0.9255812      NA   1     54 5841.28
##      endtime    oxy endoxy        rate
##   1: 6106.92 95.121 93.459 -0.02859817
##   2: 6109.10 95.066 93.422 -0.02859792
##   3: 6108.01 95.073 93.450 -0.02858670
##   4: 6105.83 95.160 93.457 -0.02858659
##   5: 6110.19 95.045 93.390 -0.02857083
##  ---                                  
## 210: 5905.64 99.001 98.323 -0.01165309
## 211: 5904.54 98.986 98.289 -0.01135471
## 212: 5903.45 98.971 98.330 -0.01091802
## 213: 5902.37 98.974 98.344 -0.01048444
## 214: 5901.28 98.981 98.386 -0.01003735
## 
## Regressions : 214 | Results : 214 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 214 adjusted rate(s):
## Rate          : -0.02859817
## Adjustment    : 0.0009187526
## Adjusted Rate : -0.02951693 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 1 rate(s) removed, 213 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 212 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     268.0955 -0.02859817 0.9975809      NA 184    237 6046.92
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 6106.92 95.121 93.459 -0.02859817 0.0009187526   -0.02951693 -0.02951693
##    oxy.unit time.unit volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0486 0.000418   NA 36 27 1.013253 -0.3352524
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -802.0392          NA  mgO2/hr/kg   -802.0392
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
57 1 CARL241 CARL239 Arlington reef 319 0.000418 ch4 Dell 0.0486 2023-04-03 2024-06-26 good/good 36 27 374.3685 0.1564861 0.981 802.0392 0.3352524 0.9975809 427.6707 0.1787663

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 265 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

2

Enter specimen data

Replicate = 2 
mass = 0.0009630 
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 April 2023 01 17PM/Oxygen"
experiment_mmr_date2 <- "03 April 2023 01 17PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0007493711

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001228393

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.66
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  7  8  9 10 11 12 13 14 15 16 18 19 20 21 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.30
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   6    1     291.2867 -0.01844004 0.985      NA 2489   2721 10521.53
## 2:   7    1     320.5017 -0.02012496 0.978      NA 2982   3215 11061.36
## 3:  11    1     353.4979 -0.01931980 0.970      NA 4957   5190 13221.41
## 4:  12    1     372.5179 -0.02001045 0.961      NA 5451   5685 13761.04
## 5:  16    1     419.9532 -0.02027690 0.982      NA 7427   7660 15920.92
## 6:  21    1     491.2516 -0.02117860 0.976      NA 9897  10130 18621.90
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1: 10775.79 96.833 92.204 -0.01844004  2.197942e-05   -0.01846202 -0.01846202
## 2: 11316.63 97.292 92.466 -0.02012496 -8.351469e-05   -0.02004144 -0.02004144
## 3: 13476.18 97.595 92.464 -0.01931980 -5.051905e-04   -0.01881461 -0.01881461
## 4: 14016.45 96.497 91.263 -0.02001045 -6.106094e-04   -0.01939984 -0.01939984
## 5: 16175.65 96.773 91.514 -0.02027690 -1.032234e-03   -0.01924467 -0.01924467
## 6: 18876.49 96.289 91.021 -0.02117860 -1.559556e-03   -0.01961904 -0.01961904
##    oxy.unit time.unit  volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.000963   NA 36 27 1.013253 -0.2147392
## 2:     %Air       sec 0.04977 0.000963   NA 36 27 1.013253 -0.2331101
## 3:     %Air       sec 0.04977 0.000963   NA 36 27 1.013253 -0.2188403
## 4:     %Air       sec 0.04977 0.000963   NA 36 27 1.013253 -0.2256473
## 5:     %Air       sec 0.04977 0.000963   NA 36 27 1.013253 -0.2238425
## 6:     %Air       sec 0.04977 0.000963   NA 36 27 1.013253 -0.2281970
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -222.9899          NA  mgO2/hr/kg   -222.9899
## 2:   -242.0666          NA  mgO2/hr/kg   -242.0666
## 3:   -227.2485          NA  mgO2/hr/kg   -227.2485
## 4:   -234.3171          NA  mgO2/hr/kg   -234.3171
## 5:   -232.4429          NA  mgO2/hr/kg   -232.4429
## 6:   -236.9647          NA  mgO2/hr/kg   -236.9647
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
57 2 CARL241 CARL239 Arlington reef 319 0.000963 ch3 Dell 0.04977 2023-04-03 2024-06-26 good/good 36 27 234.6079 0.2259274 0.9734

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.66
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row,  
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  6  9 10 11 12 13 14 16 17 18 20 25 26 27 29 32
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.31
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0     slope_b1       rsq density row endrow    time
##   1:  NA    1     506.8107 -0.061154880 0.9976023      NA 216    270 6786.77
##   2:  NA    2     506.7597 -0.061147520 0.9975977      NA 215    269 6785.67
##   3:  NA    3     506.6286 -0.061128369 0.9975900      NA 214    268 6784.38
##   4:  NA    4     506.3938 -0.061094058 0.9975724      NA 213    267 6783.29
##   5:  NA    5     505.9214 -0.061024949 0.9975191      NA 212    266 6782.20
##  ---                                                                        
## 212:  NA  212     166.3839 -0.010228592 0.8438507      NA   5     59 6552.64
## 213:  NA  213     162.5865 -0.009651599 0.8339597      NA   4     58 6551.55
## 214:  NA  214     158.9711 -0.009102097 0.8263190      NA   3     57 6550.46
## 215:  NA  215     155.8516 -0.008627908 0.8173683      NA   2     56 6549.38
## 216:  NA  216     151.9772 -0.008038976 0.7986932      NA   1     55 6548.28
##      endtime    oxy endoxy         rate
##   1: 6846.77 91.698 88.118 -0.061154880
##   2: 6845.67 91.777 88.174 -0.061147520
##   3: 6844.38 91.847 88.262 -0.061128369
##   4: 6843.29 91.907 88.332 -0.061094058
##   5: 6842.20 91.949 88.422 -0.061024949
##  ---                                   
## 212: 6612.64 99.216 98.577 -0.010228592
## 213: 6611.55 99.228 98.603 -0.009651599
## 214: 6610.46 99.238 98.656 -0.009102097
## 215: 6609.38 99.186 98.667 -0.008627908
## 216: 6608.28 99.198 98.694 -0.008038976
## 
## Regressions : 216 | Results : 216 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 216 adjusted rate(s):
## Rate          : -0.06115488
## Adjustment    : 0.0007493711
## Adjusted Rate : -0.06190425 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 22 rate(s) removed, 194 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 193 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     506.8107 -0.06115488 0.9976023      NA 216    270 6786.77
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 6846.77 91.698 88.118 -0.06115488 0.0007493711   -0.06190425 -0.06190425
##    oxy.unit time.unit  volume     mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04977 0.000963   NA 36 27 1.013253 -0.7200333
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -747.6981          NA  mgO2/hr/kg   -747.6981
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
57 2 CARL241 CARL239 Arlington reef 319 0.000963 ch3 Dell 0.04977 2023-04-03 2024-06-26 good/good 36 27 234.6079 0.2259274 0.9734 747.6981 0.7200333 0.9976023 513.0902 0.4941059

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 266 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

3

Enter specimen data

Replicate = 3 
mass = 0.0006308 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 April 2023 01 27PM/Oxygen"
experiment_mmr_date2 <- "03 April 2023 01 27PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0006606217

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001920643

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.66
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  7  8  9 10 11 12 13 14 15 16 18 19 20 21 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.30
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   2    1     299.5324 -0.02419738 0.990      NA  533    766  8361.35
## 2:  10    1     441.6427 -0.02719039 0.998      NA 4463   4697 12681.26
## 3:  16    1     485.3242 -0.02437394 0.994      NA 7427   7660 15920.92
## 4:  19    1     557.9675 -0.02624457 0.990      NA 8909   9142 17541.53
## 5:  20    1     588.5776 -0.02712049 0.983      NA 9403   9636 18081.29
## 6:  21    1     557.5565 -0.02469136 0.996      NA 9897  10130 18621.90
##     endtime    oxy endoxy        rate    adjustment rate.adjusted  rate.input
## 1:  8617.12 96.915 90.613 -0.02419738  0.0002615233   -0.02445890 -0.02445890
## 2: 12937.20 96.804 89.603 -0.02719039 -0.0008392716   -0.02635111 -0.02635111
## 3: 16175.65 97.012 90.814 -0.02437394 -0.0016646279   -0.02270931 -0.02270931
## 4: 17796.31 97.293 90.672 -0.02624457 -0.0020775882   -0.02416698 -0.02416698
## 5: 18336.08 97.762 91.077 -0.02712049 -0.0022151279   -0.02490536 -0.02490536
## 6: 18876.49 97.610 91.470 -0.02469136 -0.0023528573   -0.02233851 -0.02233851
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04593 0.0006308   NA 36 27 1.013253 -0.2625415
## 2:     %Air       sec 0.04593 0.0006308   NA 36 27 1.013253 -0.2828524
## 3:     %Air       sec 0.04593 0.0006308   NA 36 27 1.013253 -0.2437614
## 4:     %Air       sec 0.04593 0.0006308   NA 36 27 1.013253 -0.2594080
## 5:     %Air       sec 0.04593 0.0006308   NA 36 27 1.013253 -0.2673337
## 6:     %Air       sec 0.04593 0.0006308   NA 36 27 1.013253 -0.2397812
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -416.2040          NA  mgO2/hr/kg   -416.2040
## 2:   -448.4027          NA  mgO2/hr/kg   -448.4027
## 3:   -386.4322          NA  mgO2/hr/kg   -386.4322
## 4:   -411.2365          NA  mgO2/hr/kg   -411.2365
## 5:   -423.8011          NA  mgO2/hr/kg   -423.8011
## 6:   -380.1223          NA  mgO2/hr/kg   -380.1223
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
57 3 CARL241 CARL239 Arlington reef 319 0.0006308 ch2 Dell 0.04593 2023-04-03 2024-06-26 good/good 36 27 417.2153 0.2631794 0.991

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.66
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  6  7  8  9 10 11 12 13 14 15 19 20 22 24 25 27
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.08 1.30
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     477.6645 -0.05251721 0.9928955      NA 141    195 7287.69
##   2:  NA    2     477.6188 -0.05250875 0.9929351      NA 144    198 7290.95
##   3:  NA    3     477.4946 -0.05249128 0.9928864      NA 145    199 7292.03
##   4:  NA    4     477.3020 -0.05246848 0.9926924      NA 140    194 7286.60
##   5:  NA    5     477.1141 -0.05244055 0.9926740      NA 143    197 7289.87
##  ---                                                                       
## 214:  NA  214     267.4569 -0.02361555 0.9819514      NA  52    106 7189.24
## 215:  NA  215     267.0570 -0.02355981 0.9822757      NA  51    105 7188.16
## 216:  NA  216     264.0761 -0.02312554 0.9582744      NA   3     57 7134.91
## 217:  NA  217     258.4129 -0.02233538 0.9506824      NA   2     56 7133.81
## 218:  NA  218     253.5214 -0.02165281 0.9438301      NA   1     55 7132.72
##      endtime    oxy endoxy        rate
##   1: 7347.69 94.816 91.930 -0.05251721
##   2: 7350.95 94.661 91.760 -0.05250875
##   3: 7352.03 94.684 91.682 -0.05249128
##   4: 7346.60 94.791 91.911 -0.05246848
##   5: 7349.87 94.640 91.835 -0.05244055
##  ---                                  
## 214: 7249.24 97.696 96.182 -0.02361555
## 215: 7248.16 97.754 96.279 -0.02355981
## 216: 7194.91 98.806 97.537 -0.02312554
## 217: 7193.81 98.840 97.606 -0.02233538
## 218: 7192.72 98.857 97.584 -0.02165281
## 
## Regressions : 218 | Results : 218 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 218 adjusted rate(s):
## Rate          : -0.05251721
## Adjustment    : 0.0006606217
## Adjusted Rate : -0.05317783 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 218 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 217 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     477.6645 -0.05251721 0.9928955      NA 141    195 7287.69
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 7347.69 94.816  91.93 -0.05251721 0.0006606217   -0.05317783 -0.05317783
##    oxy.unit time.unit  volume      mass area  S  t        P rate.abs
## 1:     %Air       sec 0.04593 0.0006308   NA 36 27 1.013253 -0.57081
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -904.8985          NA  mgO2/hr/kg   -904.8985
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
57 3 CARL241 CARL239 Arlington reef 319 0.0006308 ch2 Dell 0.04593 2023-04-03 2024-06-26 good/good 36 27 417.2153 0.2631794 0.991 904.8985 0.57081 0.9928955 487.6832 0.3076306

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 267 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

4

Enter specimen data

Replicate = 4 
mass = 0.0007098
chamber = "ch1" 
Swim = "good/good"
chamber_vol = chamber1_dell
system1 = "Dell"
Notes=""

##--- time of trail ---## 
experiment_mmr_date <- "03 April 2023 01 37PM/Oxygen"
experiment_mmr_date2 <- "03 April 2023 01 37PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",experiment_mmr_date2,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",preexperiment_date,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0007985222

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Dell/Experiment_",postexperiment_date,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001511874

Resting metabolic rate

Data manipulation

firesting2 <- firesting |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.66
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2$TIME ==Cycle_1$Time[1], firesting$TIME)
Tstart.dTIME=as.numeric(firesting2[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2$TIME ==tail(Cycle_last$Time, n=1), firesting$TIME) 
Tend.dTIME=as.numeric(firesting2[Tend.row, "dTIME"])  

apoly_insp <- firesting2 |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  7  8  9 10 11 12 13 14 15 16 18 19 20 21 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.30
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE)  
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from selected replicates... 
## To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  16    1     506.1085 -0.02559552 0.994      NA 7427   7660 15920.92
## 2:  17    1     553.8751 -0.02766876 0.998      NA 7922   8155 16461.88
## 3:  18    1     552.1470 -0.02668578 0.996      NA 8415   8648 17001.19
## 4:  19    1     552.2181 -0.02584546 0.992      NA 8909   9142 17541.53
## 5:  20    1     623.8802 -0.02902218 0.995      NA 9403   9636 18081.29
## 6:  21    1     563.0247 -0.02492928 0.995      NA 9897  10130 18621.90
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 16175.65 98.167 92.010 -0.02559552 -0.001282724   -0.02431280 -0.02431280
## 2: 16716.81 98.185 91.275 -0.02766876 -0.001406126   -0.02626264 -0.02626264
## 3: 17255.77 98.109 91.693 -0.02668578 -0.001529089   -0.02515669 -0.02515669
## 4: 17796.31 98.452 91.974 -0.02584546 -0.001652350   -0.02419311 -0.02419311
## 5: 18336.08 98.640 91.528 -0.02902218 -0.001775457   -0.02724673 -0.02724673
## 6: 18876.49 98.475 92.503 -0.02492928 -0.001898733   -0.02303055 -0.02303055
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0465 0.0007098   NA 36 27 1.013253 -0.2642119
## 2:     %Air       sec 0.0465 0.0007098   NA 36 27 1.013253 -0.2854012
## 3:     %Air       sec 0.0465 0.0007098   NA 36 27 1.013253 -0.2733827
## 4:     %Air       sec 0.0465 0.0007098   NA 36 27 1.013253 -0.2629112
## 5:     %Air       sec 0.0465 0.0007098   NA 36 27 1.013253 -0.2960955
## 6:     %Air       sec 0.0465 0.0007098   NA 36 27 1.013253 -0.2502775
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -372.2343          NA  mgO2/hr/kg   -372.2343
## 2:   -402.0868          NA  mgO2/hr/kg   -402.0868
## 3:   -385.1545          NA  mgO2/hr/kg   -385.1545
## 4:   -370.4018          NA  mgO2/hr/kg   -370.4018
## 5:   -417.1534          NA  mgO2/hr/kg   -417.1534
## 6:   -352.6028          NA  mgO2/hr/kg   -352.6028
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple")  
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
57 4 CARL241 CARL239 Arlington reef 319 0.0007098 ch1 Dell 0.0465 2023-04-03 2024-06-26 good/good 36 27 389.4062 0.2764005 0.995

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.66
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch1
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  3  4  5  7  8  9 10 11 12 13 14 15 16 18 19 20 21 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.07 1.30
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     565.7395 -0.05970336 0.9970822      NA 159    214 7950.98
##   2:  NA    2     565.0833 -0.05962071 0.9969224      NA 160    215 7952.07
##   3:  NA    3     564.6898 -0.05957242 0.9967612      NA 158    213 7949.90
##   4:  NA    4     564.2339 -0.05953004 0.9990914      NA 104    159 7890.40
##   5:  NA    5     564.1969 -0.05952573 0.9991670      NA  95    150 7880.40
##  ---                                                                       
## 214:  NA  214     328.1328 -0.02945581 0.9564296      NA   5     60 7781.14
## 215:  NA  215     322.8098 -0.02877437 0.9540994      NA   4     59 7780.05
## 216:  NA  216     317.6860 -0.02811839 0.9512026      NA   3     58 7778.96
## 217:  NA  217     311.9253 -0.02738081 0.9471248      NA   2     57 7777.88
## 218:  NA  218     304.8910 -0.02648005 0.9408351      NA   1     56 7776.79
##      endtime    oxy endoxy        rate
##   1: 8010.98 90.904 87.550 -0.05970336
##   2: 8012.07 90.936 87.515 -0.05962071
##   3: 8009.90 91.003 87.583 -0.05957242
##   4: 7950.40 94.570 90.904 -0.05953004
##   5: 7940.40 95.117 91.570 -0.05952573
##  ---                                  
## 214: 7841.14 98.731 96.994 -0.02945581
## 215: 7840.05 98.739 97.062 -0.02877437
## 216: 7838.96 98.716 97.100 -0.02811839
## 217: 7837.88 98.664 97.119 -0.02738081
## 218: 7836.79 98.639 97.121 -0.02648005
## 
## Regressions : 218 | Results : 218 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 218 adjusted rate(s):
## Rate          : -0.05970336
## Adjustment    : 0.0007985222
## Adjusted Rate : -0.06050188 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 218 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 217 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     565.7395 -0.05970336 0.9970822      NA 159    214 7950.98
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 8010.98 90.904  87.55 -0.05970336 0.0007985222   -0.06050188 -0.06050188
##    oxy.unit time.unit volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.0465 0.0007098   NA 36 27 1.013253 -0.6574857
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -926.2972          NA  mgO2/hr/kg   -926.2972
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass, 
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
                      Notes=Notes, 
                      True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
57 4 CARL241 CARL239 Arlington reef 319 0.0007098 ch1 Dell 0.0465 2023-04-03 2024-06-26 good/good 36 27 389.4062 0.2764005 0.995 926.2972 0.6574857 0.9970822 536.891 0.3810852

Exporting data

resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 268 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

5

Enter specimen data

Replicate = 5 
mass = 0.0008477
chamber = "ch4" 
Swim = "good/good"
chamber_vol = chamber4_asus
system1 = "Asus"
Notes="check max; signal dropped during run leading to drop in % air staturation reading make sure this part of the max slope is ignored"

##--- time of trail ---## 
experiment_mmr_date_asus <- "03 April 2023 12 05PM/Oxygen"
experiment_mmr_date2_asus <- "03 April 2023 12 05PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.002228859

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------
## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.002152493

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.28
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  6  7  8 10 11 12 13 15 16 17 19 20 21 22 23 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.28
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=255, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2_asus$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  15    1     413.8223 -0.02373289 0.971      NA 5584   5771 13331.60
## 2:  16    1     445.7621 -0.02510584 0.967      NA 5981   6168 13872.51
## 3:  17    1     418.0032 -0.02227814 0.987      NA 6377   6564 14411.97
## 4:  18    1     433.5371 -0.02248750 0.983      NA 6774   6961 14952.29
## 5:  19    1     491.6074 -0.02542657 0.989      NA 7170   7357 15491.58
## 6:  21    1     514.6249 -0.02522392 0.986      NA 7964   8150 16572.34
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 13586.44 96.643 90.990 -0.02373289 -0.002142072   -0.02159082 -0.02159082
## 2: 14127.33 96.743 90.547 -0.02510584 -0.002137003   -0.02296884 -0.02296884
## 3: 14666.65 96.592 90.916 -0.02227814 -0.002131948   -0.02014619 -0.02014619
## 4: 15207.04 96.567 91.123 -0.02248750 -0.002126884   -0.02036062 -0.02036062
## 5: 15746.23 97.183 90.806 -0.02542657 -0.002121831   -0.02330474 -0.02330474
## 6: 16826.72 96.040 89.762 -0.02522392 -0.002111704   -0.02311222 -0.02311222
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.05068 0.0008477   NA 36 27 1.013253 -0.2557232
## 2:     %Air       sec 0.05068 0.0008477   NA 36 27 1.013253 -0.2720446
## 3:     %Air       sec 0.05068 0.0008477   NA 36 27 1.013253 -0.2386129
## 4:     %Air       sec 0.05068 0.0008477   NA 36 27 1.013253 -0.2411526
## 5:     %Air       sec 0.05068 0.0008477   NA 36 27 1.013253 -0.2760230
## 6:     %Air       sec 0.05068 0.0008477   NA 36 27 1.013253 -0.2737428
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -301.6671          NA  mgO2/hr/kg   -301.6671
## 2:   -320.9209          NA  mgO2/hr/kg   -320.9209
## 3:   -281.4827          NA  mgO2/hr/kg   -281.4827
## 4:   -284.4787          NA  mgO2/hr/kg   -284.4787
## 5:   -325.6141          NA  mgO2/hr/kg   -325.6141
## 6:   -322.9241          NA  mgO2/hr/kg   -322.9241
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
57 5 CARL241 CARL239 Arlington reef 319 0.0008477 ch4 Asus 0.05068 2023-04-03 2024-06-26 good/good 36 27 311.121 0.2637373 0.9792

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.64
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row+100, # custom
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch4
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 11 12 13 14 15 16 18 19 20 21 22
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 1.48
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##     rep rank intercept_b0    slope_b1       rsq density row endrow    time
##  1:  NA    1     270.1484 -0.05959728 0.9689787      NA  17     61 2988.63
##  2:  NA    2     269.7225 -0.05945966 0.9682991      NA  16     60 2987.27
##  3:  NA    3     269.3213 -0.05932039 0.9676990      NA  18     62 2989.99
##  4:  NA    4     269.2099 -0.05928082 0.9675108      NA  19     63 2991.33
##  5:  NA    5     268.1942 -0.05895657 0.9657275      NA  15     59 2985.90
## ---                                                                       
## 73:  NA   73     229.3825 -0.04618899 0.9777823      NA  53     97 3037.48
## 74:  NA   74     229.3640 -0.04618109 0.9777904      NA  57    101 3042.95
## 75:  NA   75     228.6252 -0.04594180 0.9773545      NA  54     98 3038.85
## 76:  NA   76     228.5460 -0.04591521 0.9773377      NA  56    100 3041.58
## 77:  NA   77     228.4856 -0.04589614 0.9772926      NA  55     99 3040.21
##     endtime    oxy endoxy        rate
##  1: 3048.63 91.771 88.654 -0.05959728
##  2: 3047.27 91.751 88.653 -0.05945966
##  3: 3049.99 91.818 88.647 -0.05932039
##  4: 3051.33 91.708 88.509 -0.05928082
##  5: 3045.90 91.682 88.649 -0.05895657
## ---                                  
## 73: 3097.48 89.099 86.480 -0.04618899
## 74: 3102.95 88.796 86.034 -0.04618109
## 75: 3098.85 88.999 86.337 -0.04594180
## 76: 3101.58 88.798 86.173 -0.04591521
## 77: 3100.21 88.894 86.221 -0.04589614
## 
## Regressions : 77 | Results : 77 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 77 adjusted rate(s):
## Rate          : -0.05959728
## Adjustment    : -0.002228859
## Adjusted Rate : -0.05736842 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 77 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 76 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     270.1484 -0.05959728 0.9689787      NA  17     61 2988.63
##    endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 3048.63 91.771 88.654 -0.05959728 -0.002228859   -0.05736842 -0.05736842
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.05068 0.0008477   NA 36 27 1.013253 -0.6794757
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -801.5521          NA  mgO2/hr/kg   -801.5521
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
57 5 CARL241 CARL239 Arlington reef 319 0.0008477 ch4 Asus 0.05068 2023-04-03 2024-06-26 good/good 36 27 311.121 0.2637373 0.9792 801.5521 0.6794757 0.9689787 490.4312 0.4157385 check max; signal dropped during run leading to drop in % air staturation reading make sure this part of the max slope is ignored
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 269 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

6

Enter specimen data

Replicate = 6 
mass = 0.0007758
chamber = "ch3" 
Swim = "good/good"
chamber_vol = chamber3_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "03 April 2023 12 24PM/Oxygen"
experiment_mmr_date2_asus <- "03 April 2023 12 24PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] -0.002861922

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------
## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.002872895

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.28
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  6  7  8 10 11 12 13 15 16 17 19 20 21 22 23 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.28
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:   3    1     247.2808 -0.02203073 0.986      NA  826   1006  6851.56
## 2:   4    1     251.5018 -0.02095433 0.993      NA 1223   1403  7391.83
## 3:   5    1     268.6650 -0.02166081 0.989      NA 1620   1800  7932.38
## 4:  13    1     338.5547 -0.01977671 0.999      NA 4791   4971 12251.81
## 5:  14    1     350.8316 -0.01988207 0.997      NA 5188   5368 12792.22
## 6:  15    1     361.4988 -0.01991218 0.998      NA 5584   5764 13331.60
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1:  7096.64 96.471 90.967 -0.02203073 -0.002865660   -0.01916507 -0.01916507
## 2:  7637.00 96.476 91.374 -0.02095433 -0.002866388   -0.01808794 -0.01808794
## 3:  8177.30 96.898 91.135 -0.02166081 -0.002867115   -0.01879369 -0.01879369
## 4: 12496.89 96.191 91.357 -0.01977671 -0.002872932   -0.01690378 -0.01690378
## 5: 13037.45 96.421 91.507 -0.01988207 -0.002873660   -0.01700841 -0.01700841
## 6: 13576.95 96.025 91.150 -0.01991218 -0.002874386   -0.01703779 -0.01703779
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04873 0.0007758   NA 36 27 1.013253 -0.2182586
## 2:     %Air       sec 0.04873 0.0007758   NA 36 27 1.013253 -0.2059919
## 3:     %Air       sec 0.04873 0.0007758   NA 36 27 1.013253 -0.2140292
## 4:     %Air       sec 0.04873 0.0007758   NA 36 27 1.013253 -0.1925061
## 5:     %Air       sec 0.04873 0.0007758   NA 36 27 1.013253 -0.1936978
## 6:     %Air       sec 0.04873 0.0007758   NA 36 27 1.013253 -0.1940324
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -281.3336          NA  mgO2/hr/kg   -281.3336
## 2:   -265.5219          NA  mgO2/hr/kg   -265.5219
## 3:   -275.8819          NA  mgO2/hr/kg   -275.8819
## 4:   -248.1389          NA  mgO2/hr/kg   -248.1389
## 5:   -249.6749          NA  mgO2/hr/kg   -249.6749
## 6:   -250.1062          NA  mgO2/hr/kg   -250.1062
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
57 6 CARL241 CARL239 Arlington reef 319 0.0007758 ch3 Asus 0.04873 2023-04-03 2024-06-26 good/good 36 27 264.5037 0.205202 0.9926

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.64
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.end.row, 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch3
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  5  6  7  8  9 10 11 12 13 14 16 17 18 20 21 22 23
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 1.61
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##      rep rank intercept_b0    slope_b1       rsq density row endrow    time
##   1:  NA    1     391.5154 -0.07314810 0.9758735      NA  39     84 4029.61
##   2:  NA    2     390.8276 -0.07297822 0.9756797      NA  40     85 4030.95
##   3:  NA    3     390.7300 -0.07295648 0.9771752      NA  38     83 4028.25
##   4:  NA    4     389.5218 -0.07265594 0.9767622      NA  41     86 4032.31
##   5:  NA    5     388.5818 -0.07242893 0.9757573      NA  37     82 4026.87
##  ---                                                                       
## 171:  NA  171     157.9247 -0.01681696 0.7780719      NA 158    203 4192.01
## 172:  NA  172     154.7774 -0.01608157 0.7552670      NA 162    207 4197.45
## 173:  NA  173     153.4380 -0.01575596 0.7758775      NA 159    204 4193.40
## 174:  NA  174     151.3527 -0.01526798 0.7786368      NA 161    206 4196.09
## 175:  NA  175     150.8125 -0.01513674 0.7834591      NA 160    205 4194.74
##      endtime    oxy endoxy        rate
##   1: 4089.61 96.721 92.493 -0.07314810
##   2: 4090.95 96.667 92.357 -0.07297822
##   3: 4088.25 96.637 92.520 -0.07295648
##   4: 4092.31 96.650 92.330 -0.07265594
##   5: 4086.87 96.679 92.582 -0.07242893
##  ---                                  
## 171: 4252.01 87.899 86.504 -0.01681696
## 172: 4257.45 87.585 85.829 -0.01608157
## 173: 4253.40 87.870 86.513 -0.01575596
## 174: 4256.09 87.680 86.032 -0.01526798
## 175: 4254.74 87.753 86.333 -0.01513674
## 
## Regressions : 175 | Results : 175 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 175 adjusted rate(s):
## Rate          : -0.0731481
## Adjustment    : -0.002861922
## Adjusted Rate : -0.07028618 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 107 rate(s) removed, 68 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 67 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0   slope_b1       rsq density row endrow    time
## 1:  NA    1     391.5154 -0.0731481 0.9758735      NA  39     84 4029.61
##    endtime    oxy endoxy       rate   adjustment rate.adjusted  rate.input
## 1: 4089.61 96.721 92.493 -0.0731481 -0.002861922   -0.07028618 -0.07028618
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04873 0.0007758   NA 36 27 1.013253 -0.8004437
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -1031.766          NA  mgO2/hr/kg   -1031.766
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
57 6 CARL241 CARL239 Arlington reef 319 0.0007758 ch3 Asus 0.04873 2023-04-03 2024-06-26 good/good 36 27 264.5037 0.205202 0.9926 1031.766 0.8004437 0.9758735 767.2619 0.5952418
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 270 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)

7

Enter specimen data

Replicate = 7 
mass = 0.0006812 
chamber = "ch2" 
Swim = "good/good"
chamber_vol = chamber2_asus
system1 = "Asus"
Notes=""

##--- time of trail ---## 
experiment_mmr_date_asus <- "03 April 2023 12 35PM/Oxygen"
experiment_mmr_date2_asus <- "03 April 2023 12 35PM/All"

firesting_mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date_asus,"data raw/Firesting.txt"), 
    delim = "\t", escape_double = FALSE, 
    col_types = cols(`Time (HH:MM:SS)` = col_time(format = "%H:%M:%S"), 
        `Time (s)` = col_number(), Ch1...5 = col_number(), 
        Ch2...6 = col_number(), Ch3...7 = col_number(), 
        Ch4...8 = col_number()), trim_ws = TRUE, 
    skip = 19) 
## New names:
## • `Ch1` -> `Ch1...5`
## • `Ch2` -> `Ch2...6`
## • `Ch3` -> `Ch3...7`
## • `Ch4` -> `Ch4...8`
## • `Ch 1` -> `Ch 1...9`
## • `Ch 2` -> `Ch 2...10`
## • `Ch 3` -> `Ch 3...11`
## • `Ch 4` -> `Ch 4...12`
## • `('C)` -> `('C)...15`
## • `('C)` -> `('C)...16`
## • `Ch 1` -> `Ch 1...18`
## • `Ch 2` -> `Ch 2...19`
## • `Ch 3` -> `Ch 3...20`
## • `Ch 4` -> `Ch 4...21`
## • `Ch1` -> `Ch1...22`
## • `Ch2` -> `Ch2...23`
## • `Ch3` -> `Ch3...24`
## • `Ch4` -> `Ch4...25`
## • `Ch1` -> `Ch1...26`
## • `Ch2` -> `Ch2...27`
## • `Ch3` -> `Ch3...28`
## • `Ch4` -> `Ch4...29`
## • `` -> `...31`
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
##   dat <- vroom(...)
##   problems(dat)
Cycle_1.mmr <- read_delim(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",experiment_mmr_date2_asus,"slopes/Cycle_1.txt"), 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        `Seconds from start for linreg` = col_number(), 
        `ch1 po2` = col_number(), `ch2 po2` = col_number(), 
        `ch3 po2` = col_number(), `ch4 po2` = col_number(), 
        ...8 = col_skip()), trim_ws = TRUE) 
## New names:
## • `` -> `...8`

Background rates

Pre-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",preexperiment_date_asus,"slopes")) 

pre_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

pre_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

pre_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))


bg_pre1 <- pre_cycle1 %>% calc_rate.bg()
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre2 <- pre_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre3 <- pre_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_pre <- mean(bg_pre1$rate.bg.mean,bg_pre2$rate.bg.mean,bg_pre3$rate.bg.mean) 
bg_pre
## [1] 0.0001995993

post-experiment

setwd(paste("C:/Users/jc527762/OneDrive - James Cook University/PhD dissertation/Data/2023/Resp_backup/2023_Resp/Asus/Experiment_",postexperiment_date_asus,"slopes")) 
 

post_cycle1 <- read_delim("./Cycle_1.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

post_cycle2 <- read_delim("./Cycle_2.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber)) 

post_cycle3 <- read_delim("./Cycle_3.txt", 
    delim = ";", escape_double = FALSE, col_types = cols(Time = col_time(format = "%H:%M:%S"), 
        ...8 = col_skip()), trim_ws = TRUE) %>% 
  rename(dTIME = `Seconds from start for linreg`, 
         ch1 =`ch1 po2`, 
         ch2 =`ch2 po2`, 
         ch3 =`ch3 po2`, 
         ch4 =`ch4 po2`) %>% 
  select(c("Time",chamber))

bg_post1 <- post_cycle1 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------
## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post2 <- post_cycle2 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post3 <- post_cycle3 %>% calc_rate.bg() 
## 
## # plot.calc_rate.bg # -------------------

## plot.calc_rate.bg: Plotting all 1 background rates ...
## -----------------------------------------
bg_post <- mean(bg_post1$rate.bg.mean,bg_post2$rate.bg.mean,bg_post3$rate.bg.mean)
bg_post 
## [1] -0.001687818

Resting metabolic rate

Data manipulation

firesting2_asus <- firesting_asus |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_asus, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.28
## -----------------------------------------

#### subset data

Tstart.row=which(firesting2_asus$TIME ==Cycle_1_asus$Time[1], firesting_asus$TIME) 
Tstart.dTIME=as.numeric(firesting2_asus[Tstart.row, "dTIME"]) 

Tend.row=which(firesting2_asus$TIME ==tail(Cycle_last_asus$Time, n=1), firesting_asus$TIME) 
Tend.dTIME=as.numeric(firesting2_asus[Tend.row, "dTIME"])  

apoly_insp <- firesting2_asus |> 
  subset_data(from=Tstart.dTIME, 
              to=Tend.dTIME, 
              by="time") 

apoly_insp <- inspect(apoly_insp, time=1, oxygen=2)
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  6  7  8 10 11 12 13 15 16 17 19 20 21 22 23 24
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 2.28
## -----------------------------------------

Extract rates

apoly_cr.int <- calc_rate.int(apoly_insp, 
                              starts=(195+45+300), 
                              wait=45, 
                              measure=245, 
                              by="time", 
                              plot=TRUE) 
## 
## # plot.calc_rate.int # ------------------
## plot.calc_rate.int: Plotting rate from all replicates ...
## plot.calc_rate.int: Plotting first 20 selected reps only. To plot others modify 'pos' input.

## -----------------------------------------

adjust rates for background

apoly_cr.int_adj <- adjust_rate(apoly_cr.int, 
                                by = bg_pre, 
                                by2 = bg_post, 
                                time_by = Tstart.row, 
                                time_by2 = Tend.row,
                                method = "linear")
## Warning: adjust_rate: One or more of the timestamps for the rate(s) in 'x' do not lie between the timestamps for the 'by' and 'by2' background rates. 
## Ensure this is correct. The adjustment value has been calculated regardless by extrapolating outside the background rates time window.
## Warning: adjust_rate: background rates in 'by' and 'by2' differ in sign (i.e. one is +ve, one is -ve). 
## Ensure this is correct. The 'linear' adjustment has been performed regardless.
## adjust_rate: Rate adjustments applied using "linear" method.
apoly_cr.int_adj$summary

Converting units

apoly_cr.int_adj2 <- apoly_cr.int_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253) 
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.
apoly_cr.int_adj2$summary

Plot curve

ggplot(as.data.frame(apoly_cr.int_adj2$summary), aes(x=row, y=rate.output*-1)) + 
  geom_point() + 
  stat_smooth(method = "lm", formula = y~poly(x, 2), color="red") +
  theme_classic()

Rate filtering

apoly_rmr <- apoly_cr.int_adj2 |> 
  select_rate(method ="rsq", n=c(0.95,1)) |> 
  select_rate(method="lowest", n=6) |> 
  plot(type="full") |> 
  summary(export = TRUE)
## select_rate: Selecting rates with rsq values between 0.95 and 1...
## ----- Selection complete. 0 rate(s) removed, 21 rate(s) remaining -----
## select_rate: Selecting lowest 6 *absolute* rate values...
## ----- Selection complete. 15 rate(s) removed, 6 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1   rsq density  row endrow     time
## 1:  12    1     338.1876 -0.02043935 0.989      NA 4395   4575 11712.25
## 2:  14    1     342.2430 -0.01899164 0.991      NA 5188   5368 12792.22
## 3:  17    1     402.0657 -0.02098852 0.981      NA 6377   6557 14411.97
## 4:  19    1     417.4016 -0.02052620 0.964      NA 7170   7350 15491.58
## 5:  20    1     448.9831 -0.02181877 0.978      NA 7567   7747 16031.93
## 6:  21    1     399.7676 -0.01813744 0.987      NA 7964   8143 16572.34
##     endtime    oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 11957.58 98.747 93.502 -0.02043935 -0.001569212   -0.01887014 -0.01887014
## 2: 13037.45 98.974 94.504 -0.01899164 -0.001819336   -0.01717231 -0.01717231
## 3: 14657.06 99.081 94.788 -0.02098852 -0.002194475   -0.01879404 -0.01879404
## 4: 15736.72 98.876 94.237 -0.02052620 -0.002444533   -0.01808167 -0.01808167
## 5: 16276.93 98.903 93.789 -0.02181877 -0.002569669   -0.01924910 -0.01924910
## 6: 16817.18 98.798 94.717 -0.01813744 -0.002694817   -0.01544262 -0.01544262
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04958 0.0006812   NA 36 27 1.013253 -0.2186483
## 2:     %Air       sec 0.04958 0.0006812   NA 36 27 1.013253 -0.1989755
## 3:     %Air       sec 0.04958 0.0006812   NA 36 27 1.013253 -0.2177665
## 4:     %Air       sec 0.04958 0.0006812   NA 36 27 1.013253 -0.2095123
## 5:     %Air       sec 0.04958 0.0006812   NA 36 27 1.013253 -0.2230393
## 6:     %Air       sec 0.04958 0.0006812   NA 36 27 1.013253 -0.1789337
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -320.9752          NA  mgO2/hr/kg   -320.9752
## 2:   -292.0956          NA  mgO2/hr/kg   -292.0956
## 3:   -319.6808          NA  mgO2/hr/kg   -319.6808
## 4:   -307.5635          NA  mgO2/hr/kg   -307.5635
## 5:   -327.4211          NA  mgO2/hr/kg   -327.4211
## 6:   -262.6742          NA  mgO2/hr/kg   -262.6742
## -----------------------------------------
## remove lowest slope 
apoly_rmr <- apoly_rmr |> 
  filter(rate.output != max(rate.output))

Results

results <- data.frame(Clutch = Clutch, 
                      Replicate =Replicate, 
                      Male=Male, 
                      Female=Female,
                      Population = Population, 
                      Tank = Tank,
                      Mass = mass, 
                      Chamber = chamber, 
                      System = system1,
                      Volume = chamber_vol, 
                      Date_tested = Date_tested, 
                      Date_analysed =Date_analysed,
                      Swim = Swim,
                      Salinity = salinity, 
                      Temperature = as.numeric(unique(firesting2$temperature)), 
                      Resting_kg = mean(apoly_rmr$rate.output*-1), 
                      Resting =  mean(apoly_rmr$rate.output*-1)*mass, 
                      rsqrest =mean(apoly_rmr$rsq))
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest
57 7 CARL241 CARL239 Arlington reef 319 0.0006812 ch2 Asus 0.04958 2023-04-03 2024-06-26 good/good 36 27 313.5473 0.2135884 0.9806

Maximum oxygen consumption

Data manipulation

firesting2_mmr <- firesting_mmr |>
  select(c(1:3,5:9)) |> 
  rename(TIME = `Time (HH:MM:SS)`, 
         dTIME = `Time (s)`, 
         ch1 = Ch1...5, 
         ch2 = Ch2...6,
         ch3 = Ch3...7, 
         ch4 = Ch4...8, 
         temperature= `Ch 1...9`) |> 
  select(c("dTIME",all_of(chamber),"TIME","temperature"))

Inspect file

inspect(firesting2_mmr, time=1, oxygen=2)
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.33 1.64
## -----------------------------------------

Subset data

cycle1.start <-  Cycle_1.mmr[1,1]
cycle1.end <-  tail(Cycle_1.mmr, n=1)[1,1] 

cycle1.start.row <- which(firesting2_mmr$TIME == cycle1.start); cycle1.start
## Warning in which(firesting2_mmr$TIME == cycle1.start): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1.end.row <- which(firesting2_mmr$TIME == cycle1.end); cycle1.end 
## Warning in which(firesting2_mmr$TIME == cycle1.end): Incompatible methods
## ("Ops.difftime", "Ops.data.frame") for "=="
cycle1_data <- firesting2_mmr |> 
  subset_data(from = cycle1.start.row, 
              to = cycle1.start.row+100, # custom 
              by = "row") 
## subset_data: Multi-column dataset detected in input! 
## subset_data is generally intended to subset data already passed through inspect(), or 2-column data frames where time and oxygen are in columns 1 and 2 respectively. 
## Subsetting will proceed anyway based on this assumption, but please ensure you understand what you are doing.
inspect(cycle1_data)
## inspect: Applying column default of 'time = 1'
## inspect: Applying column default of 'oxygen = 2'
## Warning: inspect: Time values are not evenly-spaced (numerically).
## inspect: Data issues detected. For more information use print().
## 
## # print.inspect # -----------------------
##                 dTIME  ch2
## numeric          pass pass
## Inf/-Inf         pass pass
## NA/NaN           pass pass
## sequential       pass    -
## duplicated       pass    -
## evenly-spaced    WARN    -
## 
## Uneven Time data locations (first 20 shown) in column: dTIME 
##  [1]  2  3  4  5  7  8  9 10 11 12 13 14 15 16 17 19 21 23 24 25
## Minimum and Maximum intervals in uneven Time data: 
## [1] 1.34 1.56
## -----------------------------------------

Calculating MMR

mmr <- auto_rate(cycle1_data, method = "highest", plot=TRUE, width=60, by="time") |> 
  summary()
## Warning: auto_rate: Multi-column dataset detected in input. Selecting first two columns by default.
##   If these are not the intended data, inspect() or subset the data frame columns appropriately before running auto_rate()

## 
## # summary.auto_rate # -------------------
## 
## === Summary of Results by Highest Rate ===
##     rep rank intercept_b0    slope_b1       rsq density row endrow    time
##  1:  NA    1     308.3401 -0.04495875 0.9910799      NA  10     54 4636.63
##  2:  NA    2     308.1651 -0.04492240 0.9909291      NA   9     53 4635.26
##  3:  NA    3     307.9286 -0.04486965 0.9907584      NA  11     55 4638.01
##  4:  NA    4     307.7282 -0.04482991 0.9905313      NA   8     52 4633.90
##  5:  NA    5     307.5529 -0.04478832 0.9904897      NA  12     56 4639.36
## ---                                                                       
## 53:  NA   53     275.4672 -0.03794276 0.9935187      NA  32     76 4666.59
## 54:  NA   54     273.3338 -0.03749020 0.9934342      NA  36     80 4672.04
## 55:  NA   55     273.2023 -0.03746086 0.9940031      NA  33     77 4667.95
## 56:  NA   56     271.9813 -0.03720180 0.9943447      NA  35     79 4670.69
## 57:  NA   57     271.9810 -0.03720128 0.9943454      NA  34     78 4669.34
##     endtime    oxy endoxy        rate
##  1: 4696.63 99.760 97.293 -0.04495875
##  2: 4695.26 99.798 97.341 -0.04492240
##  3: 4698.01 99.751 97.245 -0.04486965
##  4: 4693.90 99.810 97.357 -0.04482991
##  5: 4699.36 99.700 97.179 -0.04478832
## ---                                  
## 53: 4726.59 98.534 96.233 -0.03794276
## 54: 4732.04 98.125 95.793 -0.03749020
## 55: 4727.95 98.424 96.164 -0.03746086
## 56: 4730.69 98.233 95.943 -0.03720180
## 57: 4729.34 98.322 96.065 -0.03720128
## 
## Regressions : 57 | Results : 57 | Method : highest | Roll width : 60 | Roll type : time 
## -----------------------------------------

Adjusting

mmr_adj <- adjust_rate(mmr, by=bg_pre, method = "mean");mmr_adj
## adjust_rate: Rate adjustments applied using "mean" method.
## 
## # print.adjust_rate # -------------------
## NOTE: Consider the sign of the adjustment value when adjusting the rate.
## 
## Adjustment was applied using the 'mean' method.
## 
## Rank 1 of 57 adjusted rate(s):
## Rate          : -0.04495875
## Adjustment    : 0.0001995993
## Adjusted Rate : -0.04515835 
## 
## To see other results use 'pos' input.
## To see full results use summary().
## -----------------------------------------

Converting units

mmr_adj2 <- mmr_adj |> 
  convert_rate(oxy.unit = "%Air", 
               time.unit = "secs", 
               output.unit = "mg/h/kg", 
               volume = chamber_vol,
               mass = mass,
               S = salinity, 
               t = as.numeric(unique(firesting2$temperature)), 
               P = 1.013253)
## convert_rate: Object of class 'adjust_rate' detected. Converting all adjusted rates in '$rate.adjusted'.

selecting rates

mmr_final <- mmr_adj2 |> 
  select_rate(method = "rsq", n=c(0.93,1)) |> 
  select_rate(method = "highest", n=1) |> 
  plot(type="full") |> 
  summary(export=TRUE)
## select_rate: Selecting rates with rsq values between 0.93 and 1...
## ----- Selection complete. 0 rate(s) removed, 57 rate(s) remaining -----
## select_rate: Selecting highest 1 *absolute* rate values...
## ----- Selection complete. 56 rate(s) removed, 1 rate(s) remaining -----
## 
## # plot.convert_rate # -------------------
## plot.convert_rate: Plotting all rate(s)...

## -----------------------------------------
## 
## # summary.convert_rate # ----------------
## Summary of all converted rates:
## 
##    rep rank intercept_b0    slope_b1       rsq density row endrow    time
## 1:  NA    1     308.3401 -0.04495875 0.9910799      NA  10     54 4636.63
##    endtime   oxy endoxy        rate   adjustment rate.adjusted  rate.input
## 1: 4696.63 99.76 97.293 -0.04495875 0.0001995993   -0.04515835 -0.04515835
##    oxy.unit time.unit  volume      mass area  S  t        P   rate.abs
## 1:     %Air       sec 0.04958 0.0006812   NA 36 27 1.013253 -0.5232498
##    rate.m.spec rate.a.spec output.unit rate.output
## 1:   -768.1295          NA  mgO2/hr/kg   -768.1295
## -----------------------------------------

Results

results <-  results |> 
  mutate(Max_kg = mmr_final$rate.output*-1, 
         Max = (mmr_final$rate.output*-1)*mass,
         rsqmax =mmr_final$rsq,
         AAS_kg = Max_kg - Resting_kg, 
         AAS = Max - Resting, 
         Notes=Notes, 
         True_resting="") 
knitr::kable(results, "simple") 
Clutch Replicate Male Female Population Tank Mass Chamber System Volume Date_tested Date_analysed Swim Salinity Temperature Resting_kg Resting rsqrest Max_kg Max rsqmax AAS_kg AAS Notes True_resting
57 7 CARL241 CARL239 Arlington reef 319 0.0006812 ch2 Asus 0.04958 2023-04-03 2024-06-26 good/good 36 27 313.5473 0.2135884 0.9806 768.1295 0.5232498 0.9910799 454.5822 0.3096614
### Expor ting data
resp_results_juveniles <- read_csv("resp_results_juveniles.csv") 
## Rows: 271 Columns: 25
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr  (9): Male, Female, Population, Chamber, System, Date_tested, Swim, Note...
## dbl (16): Clutch, Replicate, Tank, Mass, Volume, Date_analysed, Salinity, Te...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
resp_results_juveniles <- rbind(resp_results_juveniles, results) 
resp_results_juveniles 
write.csv(resp_results_juveniles, file="./resp_results_juveniles.csv", row.names = FALSE)